<?php

declare(strict_types=1);

namespace App\Chat\Service;

use App\Chat\Constant\FollowUpStatusConstant;
use App\Chat\Constant\FollowUpTypeConstant;
use App\CustHub\Mapper\ChTalkFollowUpRecordMapper;
use App\CustHub\Model\ChTalkFollowUpRecord;
use Mine\Abstracts\AbstractService;

class TalkFollowUpRecordService extends AbstractService
{
    public $mapper;

    public function __construct(ChTalkFollowUpRecordMapper $mapper)
    {
        $this->mapper = $mapper;
    }

    public function getRecords(array $params)
    {
        $list = ChTalkFollowUpRecord::query()
            ->with(['customerService' => function ($query) {
                $query->select(['id','name']);
            }])
            ->where('contact_id',$params['contact_id'])
            ->orderBy('id','desc')
            ->get();

        foreach($list as $k=>$item){
            $list[$k]['type_text'] = FollowUpTypeConstant::getMessage($item['type']);
            $list[$k]['status_text'] = FollowUpStatusConstant::getMessage($item['status']);
        }
        return $list;
    }
}